home *** CD-ROM | disk | FTP | other *** search
- Path: cypher.3do.com!user
- From: tsw@3do.com (Tom Watson)
- Newsgroups: comp.lang.c
- Subject: Re: sscanf bug??????
- Date: Thu, 15 Feb 1996 16:01:24 -0800
- Organization: The 3DO Corporation
- Distribution: world
- Message-ID: <tsw-1502961601240001@cypher.3do.com>
- References: <4fimvo$82s@fnord.dfw.net> <4frr9j$ie8@fnord.dfw.net>
- NNTP-Posting-Host: cypher.3do.com
-
- In article <4frr9j$ie8@fnord.dfw.net>, jtmcap@dfw.dfw.net (Jerry Jackson) wrote:
-
- > Jerry Jackson (jtmcap@dfw.dfw.net) wrote:
- > : the following is a program compiled using microway ndp c/c++ compiler.
- > :
- > : #include <stdio.h>
- > : #include <string.h>
- > :
- > : main()
- > : {
- > : char str_1[] = "013196";
- > : char str_2[] = "13196";
- > : long res_1, res_2;
- > :
- > : sscanf(str_1,"%d",&res_1);
- > : sscanf(str_2,"%d",&res_2);
- > :
- > : printf("\nres_1 = %d",res_1);
- > : printf("\nres_2 = %d",res_2);
- > : }
- > :
- > : the output looks like this:
- > :
- > : res_1 = 89
- > : res_2 = 13196
- > :
- > :
- > : microway says that the leading zero causes sscanf to do an octal
- > : conversion on the integer. i have not found any documentation to verify
- > : this. also other compilers that i use return the value 13196 for both
- > : calls to sscanf.
- > :
- > : bug or undocumented feature?
- > :
- >
- > additional information: changing the format to sscanf(str_1,"%ld",&res_1)
- > gives the same result as sscanf(str_1,"%d",&res_1).
- >
- > also this is using microway ndp-c version 4.6.
-
- According to my sources (K&R 2, B1.3, p246, table B-2):
- %d scans a decimal integer.
- %i scans a decimal/octal/hex integer (leading non-zero, leading zero,
- leading 0x).
-
- Another source (H&S 4, 15.8, p360 table 15-4):
- %d has input format [-|+]dd..d
- %i has input format [-|+][0[x]]d..d (with footnote)
- footnote explains base conversion.
-
- Still another source (_Standard C_ by Plauger & Brodie)
- (I used the HTML version)
- Says that '%d' is the same as 'strtol' with base 10, and '%i' is the same
- as 'strtol' with base of zero (input defines).
-
- All in all it looks like you have uncovered a bug in your run-time. It
- shouldn't work like that!!
-
- I'd yell REAL loud at the vendor and tell them to FIX it.
-
- Good luck
-
- --
- Tom Watson
- tsw@3do.com (Home: tsw@johana.com)
-